//
//  UIView+HDAddMyCommunity.m
//  app
//
//  Created by D on 15/8/21.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDAddMyCommunity.h"

@implementation HDAddMyCommunity

-(id)initWithAdd:(NSString*)sign
{
    if (self = [super init]) {
        
        if (sign.integerValue == 0) {
            //添加新小区
            
            self.frame = CGRectMake(0, 0, UBO_WINDOW.width, 90);
            
            UIView * mainView = [[UIView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_1_2 ox:-UBO_WINDOW.width/2 fy:UB_1_2 oy:-30], [self.ubo ow:UBO_WINDOW.width oh:100])];
            mainView.userInteractionEnabled = YES;
            mainView.backgroundColor = [UIColor clearColor];
            [self addSubview:mainView];
            
            UIImage * BGimage = [UIImage imageNamed:@"color.png"];
            CGFloat top = 6;
            CGFloat bottom = 6;
            CGFloat left = 6;
            CGFloat right = 6;
            UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
            BGimage = [BGimage resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
            
            
            UIButton * addBtn = [[UIButton alloc]initWithFrame:CGRectOf([mainView.ufo fx:UB_1_2 ox:-(UBO_WINDOW.width-24)/2 fy:UB_1_2 oy:-20], [self.ubo ow:UBO_WINDOW.width-24 oh:40])];
            addBtn.tag = 1;
            [addBtn setTitle:@"添加我的小区" forState:UIControlStateNormal];
            [addBtn setTintColor:[UIColor whiteColor]];
            [addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [addBtn setBackgroundImage:BGimage forState:UIControlStateNormal];
            [addBtn addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:addBtn];
            
        }else
        {
            //下一步
            
            self.frame = CGRectMake(0, 0, UBO_WINDOW.width, 110);
            
            UIView * mainView = [[UIView alloc]initWithFrame:CGRectOf([self.ubo fx:UB_1_2 ox:-UBO_WINDOW.width/2 fy:UB_1_2 oy:-30], [self.ubo ow:UBO_WINDOW.width oh:110])];
            mainView.userInteractionEnabled = YES;
            mainView.backgroundColor = [UIColor clearColor];
            [self addSubview:mainView];
            
            UIImage * BGimage = [UIImage imageNamed:@"color.png"];
            CGFloat top = 6;
            CGFloat bottom = 6;
            CGFloat left = 6;
            CGFloat right = 6;
            UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
            BGimage = [BGimage resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
            
            
            UIButton * addBtn = [[UIButton alloc]initWithFrame:CGRectOf([mainView.ufo fx:UB_1_2 ox:-(UBO_WINDOW.width-24)/2 fy:UB_1_2 oy:-20], [self.ubo ow:UBO_WINDOW.width-24 oh:40])];
            addBtn.tag = 2;
            [addBtn setTitle:@"下一步" forState:UIControlStateNormal];
            [addBtn setTintColor:[UIColor whiteColor]];
            [addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [addBtn setBackgroundImage:BGimage forState:UIControlStateNormal];
            [addBtn addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:addBtn];

            
        }
        
        
        
        
    }
    return self;
}

-(void)add:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(addMyCommunityOrNext:)]) {
        [self.delegate addMyCommunityOrNext:sender];
    }
}


@end
